package controller

import (
	"ez/apps/wms/auto/controller"
	"ez/apps/wms/conf"
	wms "ez/apps/wms/document"
	"ez/custom/cc"
	"gitee.com/dreamwood/ez-go/db/mgo"
	"gitee.com/dreamwood/ez-go/ez"
)

type IOTypeController struct {
	controller.IOTypeAutoController
}

func init() {
	c := &IOTypeController{}
	c.SetRouteParam("/wms", "/admin", "IOType")
	ez.CreateApi(c.AdminGet(), c.GetAction).SetRouterName("[wms]出入库类型_创建")
	ez.CreateApi(c.AdminList(), c.ListAction).SetRouterName("[wms]出入库类型_列表")
	ez.CreateApi(c.AdminSave(), c.SaveAction).SetRouterName("[wms]出入库类型_保存")
	ez.CreateApi(c.AdminCopy(), c.CopyAction).SetRouterName("[wms]出入库类型_复制")
	ez.CreateApi(c.AdminUpdate(), c.UpdateAction).SetRouterName("[wms]出入库类型_更新")
	ez.CreateApi(c.AdminChoice(), c.ChoiceAction).SetRouterName("[wms]出入库类型_选项")
	ez.CreateApi(c.AdminDelete(), c.DeleteAction).SetRouterName("[wms]出入库类型_删除")
	ez.CreateApi(c.AdminUnDelete(), c.UnDeleteAction).SetRouterName("[wms]出入库类型_恢复")
	ez.CreateApi(c.AdminDestroy(), c.DestroyAction).SetRouterName("[wms]出入库类型_销毁")
	ez.CreateApi(c.AdminUpdateMany(), c.UpdateManyAction).SetRouterName("[wms]出入库类型_更新_批量")
	ez.CreateApi(c.AdminDeleteMany(), c.DeleteManyAction).SetRouterName("[wms]出入库类型_删除_批量")
	ez.CreateApi(c.AdminDestroyMany(), c.DestroyManyAction).SetRouterName("[wms]出入库类型_销毁_批量")
	ez.CreateApi(c.AdminTree(), c.TreeAction).SetRouterName("[wms]出入库类型_选项_树形")
	ez.CreateApi(c.AdminApi("/IOType/init"), c.InitAction).SetRouterName("[wms]出入库类型_初始化")
}

// func (c IOTypeController) AccessControl(session *ez.Session) { /* 在这里面重构 */ }
// func (c IOTypeController) GetAction(session *ez.Session) { /* 在这里面重构 */ }
// func (c IOTypeController) ListAction(session *ez.Session) { /* 在这里面重构 */ }
func (c IOTypeController) InitAction(session *ez.Session) {
	data := conf.InitIOType()
	factory := mgo.NewFactory()
	factory.SetDoc(&wms.IOType{})
	for _, t := range data {
		factory.Create(t)
	}
	wms.IOTypeTreeModel{}.UpdateLeftAndRight(0, 0, 0)
	cc.New(session).ReturnSuccess("OK111", "")
}

/*

data := conf.InitIOType()
	factory := mgo.NewFactory()
	factory.SetDoc(&wms.IOType{})

	for _, t := range data {
		_, e := ez.DBMongo.Collection(t.DocName()).InsertOne(context.TODO(), t)
		if e != nil {
			println(e.Error())
		}
	}
	//wms.IOTypeTreeModel{}.UpdateLeftAndRight(0, 0, 0)
	cc.New(session).ReturnSuccess("OK1111", "")
*/
